home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Broderbund Demo / DemoData / _menu.Dxr / 00016_MusicMgr.ls < prev    next >
Encoding:
Text File  |  1997-09-03  |  1.9 KB  |  73 lines

  1. property myChannel, myMusicList, myVolume, myPlayList, myDelay, myTime, myStatus
  2.  
  3. on new me, channelP, delayP, musicListP
  4.   set myChannel to channelP
  5.   set myMusicList to musicListP
  6.   set myPlayList to list(getAt(myMusicList, 1))
  7.   compileMusicList(me)
  8.   set myDelay to delayP
  9.   return me
  10. end
  11.  
  12. on setState me, activeState
  13.   if activeState then
  14.     set myTime to the ticks + (myDelay * 60)
  15.     if getOne(the actorList, me) = 0 then
  16.       append(the actorList, me)
  17.     end if
  18.     set myStatus to #fadeOut
  19.   else
  20.     if getOne(the actorList, me) > 0 then
  21.       deleteAt(the actorList, getOne(the actorList, me))
  22.     end if
  23.     sound fadeOut myChannel, 60
  24.   end if
  25. end
  26.  
  27. on stepFrame me
  28.   case myStatus of
  29.     #play:
  30.       if myTime > the ticks then
  31.         exit
  32.       else
  33.         set myStatus to #fadeOut
  34.         exit
  35.       end if
  36.     #start:
  37.       puppetSound(myChannel, getAt(myPlayList, 1))
  38.       set myTime to the ticks + (myDelay * 60)
  39.       set myStatus to #fadeIn
  40.     #fadeOut:
  41.       if the volume of sound myChannel > 0 then
  42.         set the volume of sound myChannel to the volume of sound myChannel - 15
  43.       else
  44.         unloadMember(getAt(myPlayList, 1))
  45.         if count(myPlayList) = 1 then
  46.           compileMusicList(me)
  47.         else
  48.           deleteAt(myPlayList, 1)
  49.         end if
  50.         set myStatus to #start
  51.       end if
  52.     #fadeIn:
  53.       if the volume of sound myChannel < 255 then
  54.         set the volume of sound myChannel to the volume of sound myChannel + 15
  55.       else
  56.         set myStatus to #play
  57.       end if
  58.   end case
  59. end
  60.  
  61. on compileMusicList me
  62.   set tempList to value(string(myMusicList))
  63.   set firstItem to getAt(myPlayList, 1)
  64.   set myPlayList to []
  65.   deleteAt(tempList, getOne(tempList, firstItem))
  66.   repeat while count(myPlayList) < (count(myMusicList) - 1)
  67.     set i to random(count(tempList))
  68.     append(myPlayList, getAt(tempList, i))
  69.     deleteAt(tempList, i)
  70.   end repeat
  71.   addAt(myPlayList, 1 + random(count(myPlayList)), firstItem)
  72. end
  73.